package main

import (
	_ "com.yt/config"
	_ "com.yt/docs"
	_ "com.yt/models"
	"com.yt/routes"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/files"
	"github.com/swaggo/gin-swagger"
	"log"
)

func main() {
	app := gin.Default()
	app.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	//跨域
	app.Use(func(c *gin.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
		c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Token, Language, From")
		c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")

		if c.Request.Method == "OPTIONS" {
			c.AbortWithStatus(204)
			return
		}
		c.Next()
	})
	app.Static("/static", "./static")
	app.Static("/js", "./static/js")
	app.Static("/img", "./static/img")
	app.Static("/css", "./static/css")
	app.StaticFile("/", "./static/index.html")
	app.StaticFile("/favicon.ico", "./static/favicon.ico")
	routes.SetRoute(app)
	log.Fatal(app.Run(":2345"))
}
